package com.yunti.springboot.controller;

import com.yunti.springboot.annotation.Log;
import com.yunti.springboot.annotation.Permission;
import com.yunti.springboot.po.ScoreRule;
import com.yunti.springboot.service.ScoreRuleService;
import com.yunti.springboot.service.SubjectService;
import com.yunti.springboot.vo.Result;
import com.yunti.springboot.vo.req.GetSubjectReq;
import com.yunti.springboot.vo.req.ScoreRuleReq;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/scoreRule")
public class ScoreRuleController {

    @Resource
    private ScoreRuleService scoreRuleService;

    @ResponseBody
    @PostMapping(value = "/getScoreRuleList")
    //通过页面大小、条数开始和结束时间对日志记录筛选
    public Result getScoreRuleList(@RequestParam("subItemId") Integer subItemId) {
        return scoreRuleService.getScoreRuleList(subItemId);
    }

    @ResponseBody
    @PostMapping(value = "/page")
    public Result findPage(@RequestBody ScoreRuleReq req) {
        return scoreRuleService.findPage(req);
    }

    @ResponseBody
    @PostMapping(value = "/getScoreByRawScore")
    //通过页面大小、条数开始和结束时间对日志记录筛选
    public Result getScoreByRawScore(@RequestParam("sex") Integer sex,@RequestParam("subItemId") Integer subItemId,@RequestParam("rawScore") String rawScore) {
        return scoreRuleService.getScoreByRawScore(sex,subItemId,rawScore);
    }

    @Log
    @ResponseBody
    @Permission({"superAdmin"})
    @PostMapping(value = "/addScoreRole")
    public Result addScoreRole(@Validated(ScoreRule.add.class) @RequestBody ScoreRule req) {
        return scoreRuleService.addScoreRole(req);
    }

    @Log
    @ResponseBody
    @Permission({"superAdmin"})
    @PostMapping(value = "/updateScoreRoleById")
    public Result updateScoreRole(@Validated(ScoreRule.edit.class) @RequestBody ScoreRule req) {
        return scoreRuleService.updateScoreRoleById(req);
    }
    @Log
    @ResponseBody
    @Permission({"superAdmin"})
    @PostMapping(value = "/delScoreRoleById")
    public Result delScoreRole(@Validated(ScoreRule.del.class) @RequestBody ScoreRule req) {
        return scoreRuleService.delScoreRoleById(req);
    }
}
